import {Toast} from 'vant'
const scanMixin={
    data() {
        return {
            
        }
    },
    created() {
        window.onScanCallBack = this.onScanCallBack;
    },
    methods: {
        setupWebViewJavascriptBridges(callback) {
            try {
              if (window.WebViewJavascriptBridge) {
                return callback(WebViewJavascriptBridge);
              }
              if (window.WVJBCallbacks) {
                return window.WVJBCallbacks.push(callback);
              }
              window.WVJBCallbacks = [callback]; // 创建一个 WVJBCallbacks 全局属性数组，并将 callback 插入到数组中。
              var WVJBIframe = document.createElement("iframe"); // 创建一个 iframe 元素
              WVJBIframe.style.display = "none"; // 不显示
              WVJBIframe.src = "wvjbscheme://__BRIDGE_LOADED__"; // 设置 iframe 的 src 属性
              document.documentElement.appendChild(WVJBIframe); // 把 iframe 添加到当前文导航上。
              setTimeout(function () {
                document.documentElement.removeChild(WVJBIframe);
              }, 0);
            } catch (error) {
              alert(error);
            }
          },
          onScanCallBack(data){
              this.waybill=data
            //   Toast.success({
            //       message:data
            //   })
          },
          scan(){
            var _this=this
            var u = navigator.userAgent;
            if (u.indexOf("Android") > -1 || u.indexOf("Linux") > -1) {
                //安卓手机
                window.NcApp.openScan();
            
                
            } else if (u.indexOf("iPhone") > -1) {
                 //苹果手机
                _this.setupWebViewJavascriptBridges(function (bridge) {
                bridge.callHandler(
                    "scanClick",
                    { data: "我进入了扫一扫页面" },
                    function (data) {
                          _this.onScanCallBack(data)             
                    }
                );
                });
               
            }
          }
          
    },
}

export default scanMixin